package com.yangzheandroid.rxmvp.http.interceptor;


import com.yangzheandroid.rxmvp.http.HttpClients;
import com.yangzheandroid.rxmvp.http.download.ProgressResponseBody;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;


public class DownloadResponseBodyInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Request.Builder requestBuilder = request.newBuilder();

        // 自定义User-Agent
        requestBuilder.addHeader("User-Agent", HttpClients.ua);

        Response originalResponse = chain.proceed(requestBuilder.build());

        return originalResponse
                .newBuilder()
                .body(new ProgressResponseBody(originalResponse.body()))//将自定义的ResposeBody设置给它
                .build();
    }
}
